package me.ingxin.android.keyboard

import android.graphics.Color
import android.view.ViewGroup
import android.widget.EditText
import androidx.appcompat.content.res.AppCompatResources
import me.ingxin.android.R
import me.ingxin.android.keyboard.entry.Key
import me.ingxin.android.keyboard.view.SafeKeyboardView
import me.ingxin.android.tools.dp2px

/**
 * Created by ingxin on 2023/2/7
 * 安全键盘管理
 */
class SafeKeyboard(editText: EditText) : BaseKeyboard<SafeKeyboardView>(editText) {

    /**安全键盘View*/
    val safeKeyboardView: SafeKeyboardView

    init {
        val ctx = editText.context
        safeKeyboardView = SafeKeyboardView(ctx).apply {
            setPadding(0, 0, 0, ctx.dp2px(8f))
            layoutParams = ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
            )
            setBackgroundColor(Color.rgb(61, 61, 61))
        }
        //设置默认样式
        keyBackground = AppCompatResources.getDrawable(ctx, R.drawable.tools_key_view_bg)
        val shift = AppCompatResources.getDrawable(ctx, R.drawable.tools_key_shift)
        val deleteD = AppCompatResources.getDrawable(ctx, R.drawable.tools_key_delete)
        val spaceD = AppCompatResources.getDrawable(ctx, R.drawable.tools_key_space)
        setKeyIcon(Key.CODE_SHIFT_LOWER, shift)
        setKeyIcon(Key.CODE_SHIFT_UP, shift)
        setKeyIcon(Key.CODE_DELETE, deleteD)
        setKeyIcon(' '.code, spaceD)
    }

    override fun getKeyboardView(): SafeKeyboardView = safeKeyboardView

}